package com.clouddot.baipai.presenter;


import com.clouddot.baipai.contract.IUrgentActivityContract;
import com.clouddot.baipai.http.entity.response.getArcticByIdResponse;
import com.clouddot.baipai.http.entity.response.getArcticListResponse;
import com.clouddot.baipai.http.entity.response.getBanPaiModelResponse;

import org.wxy.sdk.base.impl.BasePresenterImpl;

import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

public class UrgentActivityPresenter extends BasePresenterImpl<IUrgentActivityContract.IView, IUrgentActivityContract.IModel> implements IUrgentActivityContract.IPresenter {
    public UrgentActivityPresenter(IUrgentActivityContract.IView view, IUrgentActivityContract.IModel model) {
        super(view, model);
    }

    @Override
    public void getArcticList(String type, int pageindex, int pagesize) {
        Subscription subscription = mModel.getArcticList("QueryCmsPage", type, pageindex, pagesize)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<getArcticListResponse>() {
                               @Override
                               public void call(getArcticListResponse response) {
                                   mView.success(1, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(1, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }

    @Override
    public void getArcticById(String id) {
        Subscription subscription = mModel.getArcticById("GetCmsById", id)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<getArcticByIdResponse>() {
                               @Override
                               public void call(getArcticByIdResponse response) {
                                   mView.success(2, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(2, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }


    @Override
    public void getBanPaiModel() {
        if (mModel != null) {
            Subscription subscription = mModel.getBanPaiModel("GetSysParamValue", "ClassCardParam")
                    .subscribeOn(Schedulers.newThread())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Action1<getBanPaiModelResponse>() {
                                   @Override
                                   public void call(getBanPaiModelResponse response) {
                                       mView.success(3, response);
                                   }
                               }
                            , new Action1<Throwable>() {
                                @Override
                                public void call(Throwable throwable) {
                                    mView.fail(3, throwable.getMessage());

                                }
                            });
            addSubscription(subscription);
        }
    }


}
